package com.hengpeng.itfin.service.repayment;

import java.util.Date;
import java.util.List;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.itfinbase.message.partner.ReconciliationResponseMsg;
import com.hengpeng.itfinbase.message.partner.RepaymentRequestMsg;
import com.hengpeng.itfinbase.message.partner.RepaymentResponseMsg;
import com.hengpeng.itfinbase.message.partner.TrfReconciliationResponseMsg;
import com.hengpeng.itfinbase.persist.ReceivePlan.ReceiveStatus;
import com.hengpeng.itfinbase.persist.RepaymentPlan.ReplaymentStatus;

/**
 * <pre>
 * 还款追偿服务类
 * </pre>
 * 
 * @author weiyuan
 * @version 1.0, 2015年5月30日
 */
public interface RepaymentService {

    /**
     * <pre>
     * 判断当前还款计划是否已经还清
     * </pre>
     * 
     * @param borrowInfoId
     *            借款标的id
     * @param curRecNum
     *            当前还款计划期数
     * @return
     */
    public boolean checkRepaymentPlanIsRepaymented(Long borrowInfoId, Integer curRecNum);

    /**
     * 更新还款计划
     * 
     * @param borrowInfoId
     * @param newStatus
     * @param oldStatus
     * @param repayTime
     * @param updateTime
     * @param curRecNum
     * @return
     */
    public int updateRepaymentPlanStatus(Long borrowInfoId, ReplaymentStatus newStatus, ReplaymentStatus oldStatus,
            Date repayTime, Date updateTime, int curRecNum);
 
    /**
     * <pre>
     * 判断当前借款标的是否已经还清
     * </pre>
     * 
     * @param borrowInfoId
     *            借款标的id
     * @return
     */
    public boolean checkBorrowInfoIsRepaymented(Long borrowInfoId);

    /**
     * <pre>
     * 处理批次还款结果
     * </pre>
     * 
     * @param response
     */
    public ServiceResult<String> dealBatchRepaymentResult(RepaymentResponseMsg response);

    /**
     * <pre>
     * 处理还款结果
     * </pre>
     * 
     * @param response
     */
    public ServiceResult<String> dealRepaymentResult(RepaymentResponseMsg response);

    /**
     * <pre>
     * 批量还款请求前动作
     * </pre>
     * 
     * @param reqMsg
     */
    public void packBatchRepayment(RepaymentRequestMsg reqMsg);

    /**
     * <pre>
     * 还款请求前动作
     * </pre>
     * 
     * @param reqMsg
     */
    public void packRepayment(RepaymentRequestMsg reqMsg);

    /**
     * <pre>
     * 还款请求前,收款计划批次号更新
     * </pre>
     * 
     * @param receivePlanIds
     * @param batchId
     */
    public void setReceivePlanBatch(List<Long> receivePlanIds, String batchId);

    /**
     * <pre>
     * 还款对账
     * </pre>
     * 
     * @param pageNum
     * @param pageSize
     * @param beginDate
     * @param endDate
     */
    public void repaymentReconciliation(Integer pageNum, Integer pageSize, Date beginDate, Date endDate);

    /**
     * <pre>
     * 执行还款对账
     * </pre>
     * 
     * @param pageNum
     * @param pageSize
     * @param beginDate
     * @param endDate
     * @return
     */
    public ReconciliationResponseMsg doRepaymentReconciliation(Integer pageNum, Integer pageSize, Date beginDate,
            Date endDate);

    /**
     * <pre>
     * 商户扣款对账
     * </pre>
     * 
     * @param pageNum
     * @param pageSize
     * @param beginDate
     * @param endDate
     */
    public void trfReconciliation(Integer pageNum, Integer pageSize, Date beginDate, Date endDate);

    /**
     * <pre>
     * 执行商户扣款对账
     * </pre>
     * 
     * @param pageNum
     * @param pageSize
     * @param beginDate
     * @param endDate
     * @return
     */
    public TrfReconciliationResponseMsg doTrfReconciliation(Integer pageNum, Integer pageSize, Date beginDate,
            Date endDate);

    /**
     * 更新收款计划
     * 
     * @param id
     * @param newStatus
     * @param oldStatus
     * @param receiveTime
     * @param updateTime
     * @return
     */
    public int updateReceivePlanStatus(Long id, ReceiveStatus newStatus, ReceiveStatus oldStatus, Date receiveTime,
            Date updateTime);

    /**
     * 批量跟新收款计划
     * 
     * @param ids
     * @param newStatus
     * @param oldStatus
     * @param receiveTime
     * @param updateTime
     * @return
     */
    public int[] batchUpdateReceivePlanStatus(List<String> ids, ReceiveStatus newStatus, ReceiveStatus oldStatus,
            Date receiveTime, Date updateTime);
}
